<template>
  <div>
    <el-dialog
      v-toggle-full
      v-loading.lock="loading"
      class="base-dialog storage-order-details"
      :custom-class="'panna-dialog_big'"
      :append-to-body="true"
      :title="title"
      align="center"
      :close-on-click-modal="false"
      :visible.sync="innerDialogFormVisible"
      @closed="closeDialog"
    >
      <p slot="title">{{ title }}</p>
      <el-divider class="el-divider-specail" content-position="left">入库单信息</el-divider>
      <el-form id="formData" ref="formData" :model="detailData" status-icon label-width="140px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="入库单编号">
              {{ orderNum }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="创建时间">
              {{ createTime }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="入库仓库">
              {{ detailData.storageName }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业务类型">
              {{ detailData.orderTypeName }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注">
              {{ detailData.remark }}
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        ref="table"
        :data="productList"
        fit
        highlight-current-row
        :header-cell-style="{ height: '50px' }"
        :cell-style="{ height: '50px'}"
        style="width: 100%;height: auto;overflow: auto;"
      >
        <el-table-column label="危化品编号">
          <template slot-scope="scope">
            {{ scope.row.productNum }}
          </template>
        </el-table-column>
        <el-table-column label="危化品名称">
          <template slot-scope="scope">
            {{ scope.row.name }}
          </template>
        </el-table-column>
        <el-table-column label="型号规格">
          <template slot-scope="scope">
            {{ scope.row.specifications }}
          </template>
        </el-table-column>
        <el-table-column label="分类">
          <template slot-scope="scope">
            {{ scope.row.classOneName }}
          </template>
        </el-table-column>
        <el-table-column label="形态">
          <template slot-scope="scope">
            {{ scope.row.morphologyName }}
          </template>
        </el-table-column>
        <el-table-column label="存储条件">
          <template slot-scope="scope">
            {{ scope.row.storageConditionName }}
          </template>
        </el-table-column>
        <el-table-column label="包装单位">
          <template slot-scope="scope">
            {{ scope.row.unitName }}
          </template>
        </el-table-column>
        <el-table-column label="初始毛重（克）">
          <template slot-scope="scope">
            {{ scope.row.roughWeight }}
          </template>
        </el-table-column>
        <el-table-column label="生产商">
          <template slot-scope="scope">
            {{ scope.row.manufacturerName }}
          </template>
        </el-table-column>
        <el-table-column label="应收数量">
          <template slot-scope="scope">
            {{ scope.row.receiveAmount }}
          </template>
        </el-table-column>
      </el-table>
      <el-divider class="el-divider-specail" content-position="left">入库明细列表</el-divider>
      <el-table
        ref="table"
        v-loading="tableLoading"
        :data="productDetails"
        fit
        highlight-current-row
        :header-cell-style="{ height: '50px' }"
        :cell-style="{ height: '50px'}"
        style="width: 100%;height: auto;overflow: auto;"
      >
        <el-table-column label="序列号" width="150">
          <template slot-scope="scope">
            {{ scope.row.serialNum }}
          </template>
        </el-table-column>
        <el-table-column label="危化品编号">
          <template slot-scope="scope">
            {{ scope.row.productNum }}
          </template>
        </el-table-column>
        <el-table-column label="条形码" width="280">
          <template slot-scope="scope">
            <JsBarcode :value="scope.row.serialNum" :valid="true"></JsBarcode>
          </template>
        </el-table-column>
        <el-table-column label="剩余重量（克）">
          <template slot-scope="scope">
            {{ scope.row.residualWeight }}
          </template>
        </el-table-column>
        <el-table-column label="生产日期">
          <template slot-scope="scope">
            {{ scope.row.dateManufacture | dateTimeFormat }}
          </template>
        </el-table-column>
        <el-table-column label="库区">
          <template slot-scope="scope">
            {{ scope.row.storageAreaName }}
          </template>
        </el-table-column>
        <el-table-column label="库位">
          <template slot-scope="scope">
            {{ scope.row.storageSpaceName }}
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button @click="cancel">返 回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getInfo } from "../../../../api/Storage/StorageOrderIn.js";
import JsBarcode from "../../../../components/JsBarcode.vue"
import moment from 'moment';
export default {
  name: "StorageOrderInDetails",
  components: {
    JsBarcode,
  },
  filters: {
    dateTimeFormat(dateTime) {
      if (!dateTime) {
        return dateTime;
      }
      return moment(dateTime).format("YYYY-MM-DD");
    },
  },
  props: {
    dialogDetailsVisible: {
      type: Boolean,
      default: false,
    },
    readOnly: {
      type: Boolean,
      default: false,
    },
    editId: {
      type: String,
      default: '',
    },
    orderNum: {
      type: String,
      default: '',
    },
    createTime: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      title: '查看入库单信息',
      loading: false,
      tableLoading: false,
      innerDialogFormVisible: false,
      detailData: {},
      productList: [],
      productDetails: []
    };
  },
  watch: {
  },
  created() {
    this.innerDialogFormVisible = this.dialogDetailsVisible;
    this.init();
  },
  methods: {
    async init() {
      if (this.editId) {
        await this.getDetail();
      }
    },
    getDetail() {
      this.loading = true
      getInfo({ id: this.editId }).then((res) => {
        this.loading = false
        this.detailData = res.data
        this.productList = res.data.product
        this.productDetails = res.data.productDetails
      }).catch(() => {
        this.loading = false;
      });
    },
    cancel() {
      this.innerDialogFormVisible = false;
      this.$emit("update:dialogDetailsVisible", false);
      this.$emit("update:editId", "");
    },
    closeDialog() {
      this.$parent.getList();
      this.cancel();
    },
  },
};
</script>
<style lang="scss">
.storage-order-details{
  margin-top: 10px;
  width: 100%;
  .el-form{
    border: 1px solid #e6ebf5;
    .el-row{
      border-bottom: 1px solid #e6ebf5;
      &:last-child{
        border-bottom: none;
      }
      .el-col{
        &:nth-child(2n+1){
          .el-form-item{
            .el-form-item__label{
              border-left: none;
            }
          }
        }
        .el-form-item{
          margin: 0;
          height: 40px;
          line-height: 40px;
          .el-form-item__label{
            height: 100%;
            line-height: 40px;
            background: #f1f8ff;
            border-left: 1px solid #e6ebf5;
            border-right: 1px solid #e6ebf5;
            text-align: center;
            color: #909399;
            font-weight: bold;
          }
          .el-form-item__content{
            text-align: left;
            height: 100%;
            line-height: 40px;
            margin-left: 20px;
          }
        }
      }
    }
  }
  .el-divider-specail{
    background: transparent;
    .el-divider__text{
      font-weight: bold;
      font-size: 15px;
      left: -20px;
    }
    &.el-divider-top{
      margin-top: 60px;
    }
  }
}
</style>
